---
title: "Replication material for 'Why Do Citizens (Not) Support Democratic Innovations? The Role of Instrumental Motivations in Support for Participatory Budgeting'"

author: | 
        | Ramon van der Does
        | Jaroslaw Kantorowicz

date: |
      | January 18, 2021
      
output: html_notebook
---

# Installing/loading required packages

```{r}

#install.packages("cregg")
#install.packages("cjoint")
#install.packages("tidyverse")
#devtools::install_github("jaredhuling/jcolors")
#install.packages("ggpubr")
#install.packages("arm")
#install.packages("GGally")
#install.packages("grid")

library(cregg)
library(cjoint)
library(tidyverse)
library(jcolors)
library(ggpubr)
library(arm)
library(GGally)
library(grid)

```


# Load data for study 3

```{r}

rat_efficiency_final <- read.csv(file="study_3.csv")

rat_efficiency_final$residents_allowed_submit <- as.factor(rat_efficiency_final$residents_allowed_submit)
rat_efficiency_final$projects_allowed <- as.factor(rat_efficiency_final$projects_allowed)
rat_efficiency_final$support_municipality <- as.factor(rat_efficiency_final$support_municipality)
rat_efficiency_final$choice_winning_project <- as.factor(rat_efficiency_final$choice_winning_project)
rat_efficiency_final$outcome_favorability <- as.factor(rat_efficiency_final$outcome_favorability)
rat_efficiency_final$final_cost <- as.factor(rat_efficiency_final$final_cost)


```

### Assumption checks

```{r}

cj_anova(rat_efficiency_final, selected ~ 
                                residents_allowed_submit +
                                projects_allowed +
                                support_municipality + 
                                choice_winning_project +
                                outcome_favorability +
                                final_cost, 
                                by = ~task, 
                                id = ~responseid)
        
cj_anova(rat_efficiency_final, selected ~ 
                                residents_allowed_submit +
                                projects_allowed +
                                support_municipality + 
                                choice_winning_project +
                                outcome_favorability+
                                final_cost, 
                                by = ~profile, 
                                id = ~responseid)

```


### Figure 3 Results study 3

```{r}

rat_efficiency_final <- rat_efficiency_final %>% mutate(profile2=ifelse(profile==1, 
                                                                        "Left", 
                                                                        "Right"))

rat_efficiency_final$profile2 <- as.factor(rat_efficiency_final$profile2)


rat_efficiency_final$final_cost <- factor(rat_efficiency_final$final_cost, 
                                          levels = c("Exactly as planned",
                                                     "5% more than planned",
                                                     "25% more than planned",
                                                     "50% more than planned"))


rat_efficiency_final$support_municipality <- factor(rat_efficiency_final$support_municipality, 
                                                    levels= c("No extra support", 
                                                              "Organizing discussion", 
                                                              "Helping to develop the project"))



rat_amce_efficiency <- cj(rat_efficiency_final,
              selected ~ 
                      residents_allowed_submit + 
                      projects_allowed + 
                      support_municipality + 
                      choice_winning_project + 
                      outcome_favorability +
                      final_cost +
                      profile2, 
                      id = ~responseid, 
                      estimate = "amce",
                      feature_order = c("residents_allowed_submit",
                                        "projects_allowed",
                                        "support_municipality",
                                        "choice_winning_project",
                                        "outcome_favorability",
                                        "final_cost",
                                        "profile2"),
                      feature_labels = c(residents_allowed_submit = "Who can submit a project?", 
                                         projects_allowed = "What projects are allowed?",
                                         outcome_favorability = "Is the outcome favorable?", 
                                         support_municipality = "Does the muninicipality offer any support?", 
                                         choice_winning_project="Who is choosing the winning project?",
                                         final_cost = "What is the final cost of the project?",
                                         profile2 = "Profile"))



plot_rat_amce_efficiency <- plot(rat_amce_efficiency, 
                     vline=0.0, 
                     size=1, 
                     feature_headers = FALSE)

plot_rat_amce_final_efficiency <- plot_rat_amce_efficiency +
           theme(legend.position="none") + 
           theme(axis.text.y = element_text(colour = "black")) +
           theme(axis.text.x = element_text(colour = "black")) +
           theme(plot.title = element_text(hjust = 1.0, vjust = 3)) +
           theme(text = element_text(size=15))  +
           ggplot2::facet_wrap(~feature, ncol=1, scales = "free_y") +
           geom_text(subset(rat_amce_efficiency, estimate!=0), mapping=aes(label=round(estimate,3)), 
                     parse = TRUE, color="black", size=3, check_overlap = TRUE, 
                     vjust = 1.4) +scale_color_jcolors("pal11") +
          theme(panel.grid.major = element_blank(),
           panel.grid.minor = element_blank(),
           strip.background = element_blank(),
           panel.border = element_rect(colour = "black"))
            

plot(plot_rat_amce_final_efficiency)

plot_rat_amce_final_efficiency %>% ggsave(filename = "figure_4.png",
                                width = 8, 
                                height = 8, 
                                dpi = 150, 
                                units = "in", 
                                device='png')

```
